import axios from 'axios'

const API_BASE_URL = '/storage'

/**
 * 存储策略API工具类
 */
export class StorageApi {
  
  /**
   * 获取当前存储策略
   */
  static async getCurrentStrategy() {
    try {
      const response = await axios.get(`${API_BASE_URL}/current`)
      return response.data
    } catch (error) {
      console.error('获取当前存储策略失败:', error)
      throw error
    }
  }
  
  /**
   * 获取所有可用存储策略
   */
  static async getAllStrategies() {
    try {
      const response = await axios.get(`${API_BASE_URL}/strategies`)
      return response.data
    } catch (error) {
      console.error('获取存储策略列表失败:', error)
      throw error
    }
  }
  
  /**
   * 检查存储策略是否可用
   */
  static async checkStrategy(storageType) {
    try {
      const response = await axios.get(`${API_BASE_URL}/check/${storageType}`)
      return response.data
    } catch (error) {
      console.error('检查存储策略失败:', error)
      throw error
    }
  }
  
  /**
   * 测试存储策略连接
   */
  static async testStrategy(storageType) {
    try {
      const response = await axios.post(`${API_BASE_URL}/test/${storageType}`)
      return response.data
    } catch (error) {
      console.error('测试存储策略失败:', error)
      throw error
    }
  }
}

/**
 * 存储策略类型常量
 */
export const StorageTypes = {
  LOCAL: 'local',
  MINIO: 'minio',
  OSS: 'oss'
}

/**
 * 存储策略显示名称映射
 */
export const StorageTypeNames = {
  [StorageTypes.LOCAL]: '本地存储',
  [StorageTypes.MINIO]: 'MinIO对象存储',
  [StorageTypes.OSS]: '阿里云OSS'
}

/**
 * 存储策略图标映射
 */
export const StorageTypeIcons = {
  [StorageTypes.LOCAL]: 'folder',
  [StorageTypes.MINIO]: 'coin',
  [StorageTypes.OSS]: 'cloudy'
} 